/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package task20;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


/**
 *
 * @author Administrator
 */
public class Notices {
    
    public String getTodayName(){        
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();        
        calendar.setTime(date);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");             
        return formatter.format(date);
    }
    
    public String getTomorrowName(){        
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();        
        calendar.setTime(date);
        calendar.add(calendar.DATE, 1);
        date = calendar.getTime();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");             
        return formatter.format(date);
    }
    
    
    public ArrayList getTodayNotices(){
        ArrayList l = null;
        try{
            File file = new File("notices/"+getTodayName()+".txt");
            if(file.exists()){
                l = new ArrayList();
                FileReader f = new FileReader(file);
                BufferedReader b = new BufferedReader(f);
                String temp = null;                
                while((temp=b.readLine())!=null){
                    l.add(temp);
                }
                
            }
            return l;
        } catch (Exception ex) {                
                return null;
       } 
    }
    
    public boolean setTomorrowNotice(String notice){
        try {
            File file = new File("notices");
            if(!file.exists()){
                file.mkdir();
            }
            file = new File("notices/"+getTomorrowName()+".txt");
            if(!file.exists()){
                file.createNewFile();
            }
            
            FileOutputStream f = new FileOutputStream(file,true);
            PrintWriter p = new PrintWriter(f,true);
            p.println(notice);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    public static void main(String[] args) {
        
        Notices nt = new Notices();
        System.out.println(nt.getTodayName());
        System.out.println(nt.getTomorrowName());
    }
    
    
    

}
